<?php
class IdiomaComponent extends Object {
	public $controller = null;
	public $languages = array();
	public $components = array('Cookie','Session'); 
	public function initialize($controller) {
		$this->controller = $controller;
	}

	function _idioma(){
	
		// Defino el Timezone del Client
		date_default_timezone_set($_SESSION['Client']['timezone']);
		$lang = $this->Session->read('Auth.User.idioma');
		
		//---------------------------------------------------------
		//                 guardar en cookie el idioma que queremos
		//---------------------------------------------------------
		if(!empty($lang)){
			Configure::write('Config.language', $lang);
            $this->Session->write('Config.language', $lang);  
			$this->Cookie->write('language', $lang, false, '20 days');  
			
		} elseif ( !$this->Cookie->read('language') AND !$this->Session->check('Config.language')) {  
			$lang = 'spa';
			Configure::write('Config.language', $lang);
            $this->Session->write('Config.language', $lang);  
			$this->Cookie->write('language', $lang, false, '20 days');  
			
		} elseif( $this->Cookie->read('language') ) {
			$lang = $this->Cookie->read('language');
			Configure::write('Config.language', $lang);
            $this->Session->write('Config.language', $lang);  
			
		} else {
			$lang = $this->Session->read('Config.language');
			Configure::write('Config.language', $lang);
            $this->Cookie->write('language', $lang, false, '20 days');  
		}
		
	}
    
}
?>